<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Tbag <897498621@qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
// Uploadify.class.php 2013年3月22日8:09:05

class UploadifymAction extends Action{	
	public function upload(){
        if (!empty($_FILES)) {
			    import('@.ORG.UploadFile');
				$upload = new UploadFile();
					//设置上传文件大小 
				$upload->maxSize            = 2000000;
					//设置上传文件类型
				$upload->allowExts          = explode(',', 'jpg,gif,png,jpeg');
					//设置附件上传目录
				$upload->savePath 			=  './Public/images/memberhead/';
					//设置需要生成缩略图，仅对图像文件有效
				$upload->thumb              = true;
					// 縮略圖路徑
				$upload->thumbPath         =  './Public/images/memberhead/thumb/';
				// 设置引用图片类库包路径
				$upload->imageClassPath     = '@.ORG.Image';
					//设置需要生成缩略图的文件后缀
				$upload->thumbPrefix        = 'm_,s_';  //m_大缩略图，s_小缩略图
					//设置缩略图最大宽度
				$upload->thumbMaxWidth      = '80,40';
					//设置缩略图最大高度
				$upload->thumbMaxHeight     = '80,40';
					//设置上传文件规则
				$upload->saveRule           = 'uniqid';
            if (!$upload->upload()) { // 上传错误提示错误信息
				$error['message'] = $upload->getErrorMsg();
                $error['status'] = 0;
			    echo json_encode($error);
                exit;
            } else {
                // 上传成功 获取上传文件信息
                $info = $upload->getUploadFileInfo();
                $info[0]['file'] = __ROOT__.trim($info[0]['savepath'].$info[0]['savename'],'.');
				$info[0]['file_name'] =  $info[0]['savename'];
                echo json_encode($info[0]);
                exit;
            }
        }
	}

	/**
	 * 删除上传到图片
	 */
	public function removeImg(){
		$file = $_GET['file'];
		@unlink("./Public/images/memberhead/".$file);
		@unlink("./Public/images/memberhead/thumb/m_".$file);
		@unlink("./Public/images/memberhead/thumb/s_".$file);
	}
}